package com.yingxin.yx.framework.commons.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.yingxin.yx.framework.commons.activiti.dto.ActivitiInstanceDto;
import com.yingxin.yx.framework.commons.dto.AttachmentDto;
import com.yingxin.yx.framework.render.core.model.Form;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * @author fanchao
 */

@Data
public class CommonRespVo implements Serializable {

    /**
     * 单据名称
     */
    protected String billTypeName;

    // 用于app的表单渲染
    protected Form renderForm;

    // 附件
    @ApiModelProperty(value = "附件列表")
    protected List<AttachmentDto> attachmentList;

    // 流程
    @ApiModelProperty(value = "流程对象")
    protected ActivitiInstanceDto activitiInstance;

    @ApiModelProperty(value = "流程实例id")
    protected String processInstanceId;

    @ApiModelProperty(value = "任务id")
    protected String taskId;

    // businessId
    @ApiModelProperty(value = "businessId")
    protected String businessId;

    @ApiModelProperty(value = "businessNo")
    protected String businessNo;

    // businessType
    @ApiModelProperty(value = "businessType")
    protected String businessType;

    /**
     * 创建者id
     */
    @ApiModelProperty("创建人,添加人,申请人,操作人,出库人,入库人 id")
    protected String creatorId;

    /**
     * 创建者名称
     */
    @ApiModelProperty("创建人,添加人,申请人,操作人,出库人,入库人 名称")
    protected String creatorName;

    /**
     * 创建时间
     */
    @ApiModelProperty("创建,添加,申请,操作,出库,入库 时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
    protected Date createTime;

    /**
     * 更新者id
     */
    @ApiModelProperty("更新者id")
    protected String updaterId;

    /**
     * 更新者名称
     */
    @ApiModelProperty("更新者名称")
    protected String updaterName;

    /**
     * 更新时间
     */
    @ApiModelProperty("更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
    protected Date updateTime;

    /**
     * 打印人id
     */
    @ApiModelProperty(value = "打印人id")
    protected String printerId;

    /**
     * 打印人名称
     */
    @ApiModelProperty(value = "打印人名称")
    protected String printerName;

    /**
     * 打印时间
     */
    @ApiModelProperty(value = "打印时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
    protected Date printTime;

    /**
     * 打印次数
     */
    @ApiModelProperty(value = "打印次数")
    protected Integer printCount;

    @ApiModelProperty("创建人,添加人,申请人,操作人,出库人,入库人 的部门id")
    protected String creatorDeptId;

    @ApiModelProperty("创建人,添加人,申请人,操作人,出库人,入库人 的部门名称")
    protected String creatorDeptName;

    private String subtotalField;

    @ApiModelProperty(value = "小计标记")
    private String subtotalFlag = "0";

    // 颜色code
    private String rowColor;

    /**
     * 作废人ID
     */
    private String invalidId;

    /**
     * 作废人姓名
     */
    private String invalidName;

    /**
     * 作废时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
    private Date invalidTime;

    /**
     * 作废备注
     */
    private String invalidRemarks;

    /**
     * 作废申请单ID
     */
    private String applyId;

    /**
     * 作废申请单编号
     */
    private String applyNo;

    // setActivitiInstance 顺便set businessId businessNo businessType，不一定有值
    public void setActivitiInstance(ActivitiInstanceDto activitiInstance) {
        this.activitiInstance = activitiInstance;
        if (activitiInstance != null) {
            this.taskId = activitiInstance.getTaskId();
            if (this.businessId == null) {
                this.businessId = activitiInstance.getBillId();
            }
            if (this.businessNo == null) {
                this.businessNo = activitiInstance.getBillNo();
            }
            if (this.businessType == null) {
                this.businessType = activitiInstance.getBillType();
            }
        }
    }


    // setAttachmentList 顺便set businessId businessNo businessType，不一定有值
    public void setAttachmentList(List<AttachmentDto> attachmentList) {
        this.attachmentList = attachmentList;
        if (attachmentList != null && attachmentList.size() > 0) {
            if (this.businessId == null) {
                this.businessId = attachmentList.get(0).getBusinessId();
            }
            if (this.businessNo == null) {
                // this.businessNo = attachmentList.get(0).getno();
            }
            if (this.businessType == null) {
                this.businessType = attachmentList.get(0).getBusinessType();
            }
        }
    }
}